var server = require('http');
var mysql = require('mysql');
var pool;
var result;
server.createServer(
		function(req, res) {
			console.log('deal with url of:.', req.url);
			res.writeHead(200, {
				'content-type' : 'text-plain'
			});
			getPool().query('select count(*) as result from sys_area',
					function(err, rows, fields) {
						// console.log(fields);
						result = rows[0].result;
						console.log('The solution is: ', rows[0].result);
					});
			res.end('your sql search result is:' + result);
		}).listen(8080, "127.0.0.1");

function getPool() {
	if (!pool) {
		console.log('init pool now.');
		pool = mysql.createPool({
			connectionLimit : 5,
			host : 'localhost',
			user : 'root',
			password : 'root',
			database : 'tenmalife-platform'
		});
	}
	return pool;
}